﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Web.Mvc;
using System.Web.Security;
using ManticLabs.Data;
using System.Data.Common;

namespace CPRApp.Models
{
    public class BookingModel
    {
        [Required]
        [Display(Name = "Booking Id")]
        public int BookingId { get; set; }

        [Required]
        [DataType(DataType.Date)]
        [Display(Name = "Item Receipt Date")]
        public DateTime ReceiptDate { get; set; }

        [Required]
        [Display(Name = "Customer Name")]
        public string CustomerName { get; set; }

        [Required]
        [Display(Name = "Item Model")]
        public string ItemModel { get; set; }

        [Required]
        [Display(Name = "Item Details")]
        public string ItemDetails { get; set; }

        [Required]
        [Display(Name = "Item Condition")]
        public string ItemCondition { get; set; }

        [Required]
        [DataType(DataType.DateTime)]
        [Display(Name = "Estimate Delivery Time")]
        public DateTime EstimateDeliveryTime { get; set; }

        [Required]
        [Display(Name = "Estimate Bill Amount")]
        public int EstimateBillAmount { get; set; }

        [Required]
        [Display(Name = "Issues Reported")]
        public string IssuesReported { get; set; }

        [Required]
        [Display(Name = "Is Under Warrenty")]
        public bool IsInWarrenty { get; set; }

        [Required]
        [Display(Name = "Technicion Name")]
        public string Technicion { get; set; }

        [Required]
        [Display(Name = "Entered By")]
        public string EnteredBy { get; set; }

        public string[] ConditionsList
        {
            get
            {
                return new string[] { "New", "Old Not Repaired", "Old Repaired" };
            }
        }


    }

    public class BillModel
    {
        public BookingModel Booking { get; set; }

        [Required]
        [DataType(DataType.DateTime)]
        [Display(Name = "Work Start Time")]
        public DateTime WorkStartTime { get; set; }

        [Required]
        [DataType(DataType.DateTime)]
        [Display(Name = "Delivery Time")]
        public DateTime DeliveryTime { get; set; }

        [Required]
        [Display(Name = "Bill Amount")]
        public int BillAmount { get; set; }

        [Required]
        [Display(Name = "Cost Amount")]
        public int CostAmount { get; set; }

        [Required]
        [Display(Name = "Time Spent")]
        public int TimeSpent { get; set; }

        [Required]
        [Display(Name = "Issues Found")]
        public string IssuesFound { get; set; }

        [Required]
        [Display(Name = "Issues Fixed")]
        public string IssuesFixed { get; set; }

    }

    public class BookingListModel : List<BookingModel>
    {
        public IEnumerable<BookingModel> GetBookings()
        {
            BookingListModel bookings = new BookingListModel();
            DataAccessOleDB da = new DataAccessOleDB();
            DbDataReader dr = (DbDataReader)da.GetRowsAsOleDbDataReader(ResultType.SingleResult, "select * from ServiceOrder");

            while (dr.Read())
            {
                BookingModel bm = new BookingModel();
                bm.BookingId = Convert.ToInt32(dr["BookingId"].ToString());
                bm.CustomerName = dr["CustomerName"].ToString();
                bm.EnteredBy = dr["EnteredBy"].ToString();
                bm.EstimateBillAmount = Convert.ToInt32(dr["EstBillAmount"].ToString());
                bm.EstimateDeliveryTime = Convert.ToDateTime(dr["EstDeliveryTime"].ToString());
                bm.IsInWarrenty = Convert.ToBoolean(dr["IsInWarrenty"].ToString());
                bm.IssuesReported = dr["IssuesReported"].ToString();
                bm.ItemCondition = dr["ItemCondition"].ToString();
                bm.ItemDetails = dr["ItemDetails"].ToString();
                bm.ItemModel = dr["ItemModel"].ToString();
                bm.ReceiptDate = Convert.ToDateTime(dr["ReceiptDate"].ToString());
                bookings.Add(bm);
            }
            return bookings;
        }
    }
}